import request from '@utils/request';
import * as actionTypes from './actionType';
import { message } from 'antd';

//获取所有订单
export const getAllOrderRequest = (values) => {
    return (dispatch) => {
        request('POST', '/api/server/web/rest/order/getAllOrders', {
            cmd: 'getAllOrders',
            type: 'request',
            request: {
               ...values 
            }
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                let result = res.message;
                dispatch(getAllOrderUpdateReducer(result))
            } else {
                message.error('获取数据失败' + res.exception, 1);
            }
        }).catch(err => console.log(err));
    }
}
const getAllOrderUpdateReducer = (getAllOrder) => ({
    type: actionTypes.ALLORDER,
    getAllOrder
})

//删除数据
export const deleteOrderRequest = (value) => {
    return (dispatch) => {
        request('POST', '/api/server/web/rest/order/deleteOrder', {
            cmd: 'deleteOrder',
            type: 'request',
            request: {
                ...value
            }
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                message.success('已删除!', 1);
                dispatch(getAllOrderRequest())
            } else {
                message.error('添加失败' + res.exception, 1);
            }
        }).catch(err => console.log(err));
    }
}